package view.toolboxComponents;

import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JLabel;
import javax.swing.JTextField;
import controller.CustomEvent;
import controller.EventHandler;
import controller.ToolBoxEventHandler;/** * A class to encapsulate the serial number panel on the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
@SuppressWarnings("serial")
public class PrescriptionSerialNumberPanel extends AbstractPanel{
	private JLabel lblPresSerialNum;
	private JTextField txtPresSerialNum;
	private EventHandler eventHandler;	
	public PrescriptionSerialNumberPanel(){
		super();
		lblPresSerialNum = new JLabel("Serial");
		txtPresSerialNum = new JTextField();
		txtPresSerialNum.setMaximumSize(new Dimension(120,20));
		buildPanel();		
		txtPresSerialNum.addKeyListener(new KeyListener(){			
			@Override
			public void keyPressed(KeyEvent e) {
			}
			@Override
			public void keyReleased(KeyEvent arg0) {
				CustomEvent event = new CustomEvent("presSerialNumberChange", this, txtPresSerialNum.getText());
				PrescriptionSerialNumberPanel.this.eventHandler = new ToolBoxEventHandler();
				PrescriptionSerialNumberPanel.this.eventHandler.createEvent(event);
			}
			@Override
			public void keyTyped(KeyEvent arg0) {
			}
		});
	}
	/**
	 * Set the text in the textfield to specified text
	 * @param String text
	 */
	public void setText(String text){
		txtPresSerialNum.setText(text);
	}
	/**
	 * Build prescription name panel
	 */
	private void buildPanel() {
		this.add(lblPresSerialNum);
		makeRigidArea();
		this.add(txtPresSerialNum);
	}	@Override
	public void resetComponent(){
		txtPresSerialNum.setText("");
	}
}